package com.version.manager.service.Shop;

import com.version.manager.entity.Shop.shopUser;
import com.version.manager.mapper.Shop.shopUserMapper;
import com.version.manager.model.Msg;
import com.version.manager.service.BaseService;
import com.version.manager.util.DateTimeUtil;
import com.version.manager.util.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class shopUserService extends BaseService<shopUserMapper, shopUser> {

    public Msg regist(shopUser user) throws Exception {
        Map<String,Object> map=new HashMap<>();
        map.put("openId",user.getOpenId());
        QueryParam queryParam=new QueryParam(map);
        List<shopUser> find=super.selectList(queryParam);
        if(find.size()==0){
            user.setId(user.getOpenId());
            user.setCreateTime(DateTimeUtil.getStringDate());
            user.setStatus("1");
            super.mapper.insert(user);
        }else{
            user.setId(user.getOpenId());
        }
        return Msg.success().addData(user);
    }
}
